/**
 * Copyright [2019] [LiBo/Alex of copyright liboware@gmail.com ]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.algorithm.leetcode;

import java.util.Arrays;

/**
 * @project-name:coffice-toolbox
 * @package-name:com.hyts
 * @author:LiBo/Alex
 * @create-date:2019-10-27 05:26
 * @copyright:libo-alex4java
 * @email:liboware@gmail.com
 * @description:
 */
public class TestTempary {


    private static final int [] arrays = {1,2,2,3,4,5};


    public static void main(String[] args){
        int len = arrays.length;
        int stablePosition = 0;
        for(int i = 0 ; i< len ;i++){
            int [] tempArray = new int[arrays.length];
            System.arraycopy(arrays,0,tempArray,0,tempArray.length);
            stablePosition = i;
            System.out.println("------------"+stablePosition+"----------------");
            for(int j = 0 ; j<len;j++){
                if(j == stablePosition){
                    continue;
                }else{
                    for(int k = j+1;k<len;k++){
                        System.arraycopy(arrays,0,tempArray,0,tempArray.length);
                        if(k == stablePosition || ((k==2 && tempArray[j] ==4) ||
                                (j==2 && tempArray[k] ==4)) ||(
                                tempArray[k] == 3 && (tempArray[Math.min(j+1,len-1)] ==5 ||
                                        tempArray[Math.max(j-1,0)] == 5) ||
                                        tempArray[k] == 5 && (tempArray[Math.min(j+1,len-1)] ==3||
                                                tempArray[Math.max(j-1,0)] == 3)
                                        ||(
                                        tempArray[j] == 3 && (tempArray[Math.min(k+1,len-1)] ==5 ||
                                                tempArray[Math.max(k-1,0)] == 5) ||
                                                tempArray[j] == 5 && (tempArray[Math.min(k+1,len-1)] ==3||
                                                        tempArray[Math.max(k-1,0)] == 3)))
                        ){
                            continue;
                        }
                            int temp = tempArray[j];
                            tempArray[j] = tempArray[k];
                            tempArray[k] = temp;
                            System.out.println(Arrays.toString(tempArray));
                    }
                }
            }
            tempArray = null;

        }
    }

}


